home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Shareware Grab Bag
/
Shareware Grab Bag.iso
/
090
/
byt86jan.arc
/
LCM.BAS
< prev
next >
Wrap
BASIC Source File
|
1985-12-27
|
2KB
|
41 lines
10 '**********************************************
20 '* LEAST COMMON MULTIPLE ALGORITHM *
30 '* BY ROBERT T. KUROSAKA *
40 '**********************************************
50 CLS
60 PRINT "This program calculates the least common multiple"
70 PRINT "of a set of positive integers."
80 PRINT
90 INPUT "HOW MANY INTEGERS ARE IN THE SET";TERMS:TERMS=INT(ABS(TERMS))
100 IF TERMS<2 THEN 400
110 REM NUMBER ARRAY HOLDS THE SET OF INTEGERS FOR WHICH THE LCM IS SOUGHT.
120 DIM NUMBER(TERMS)
130 PRINT :PRINT "ENTER THE INTEGERS ONE AT A TIME."
140 FOR I=1 TO TERMS
150 INPUT NUMBER(I)
160 NUMBER(I)=INT(ABS(NUMBER(I)))
170 IF NUMBER(I)=0 THEN PRINT "ILLEGAL ENTRY.":GOTO 150
180 NEXT I
190 REM BEGIN LCM PROCEDURE.
200 LCM=NUMBER(1) 'THE LCM OF A SINGLE NUMBER IS ITSELF.
210 FOR I=2 TO TERMS
220 REM FIND GCD OF ACTIVE ENTRY AND WHAT PRECEDED IT (GCD WILL BE STORED IN `DIVIDEND' BECAUSE LINE 290 ASSIGNS LAST VALID DIVISOR TO DIVIDEND).
230 DIVISOR=NUMBER(I):DIVIDEND=LCM
240 REM LINES 250-300 ARE THE SAME AS 450-500 OF THE GCD ROUTINE.
250 IF DIVISOR>DIVIDEND THEN SWAP DIVISOR,DIVIDEND
260 WHILE DIVISOR>0
270 QUOTIENT=INT(DIVIDEND/DIVISOR)
280 REMAINDER=DIVIDEND-DIVISOR*QUOTIENT
290 DIVIDEND=DIVISOR:DIVISOR=REMAINDER
300 WEND
310 LCM=NUMBER(I)*LCM/DIVIDEND
320 REM THE LAST LCM WILL BE LCM OF ALL THE ENTRIES.
330 NEXT I
340 PRINT :PRINT
350 PRINT "THE LEAST COMMON MULTIPLE OF";
360 FOR I=1 TO TERMS
370 PRINT NUMBER(I);
380 NEXT I
390 PRINT "IS";LCM
400 END